<template>
  <div class="app-container">
    <el-card>
      <!--工具栏-->
      <div class="head-container">
        <eHeader :permission="permission"/>
        <crudOperation :permission="permission" />
      </div>
      <!--工具栏-->

      <!--表单组件-->
      <eForm  />

      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="studentId" label="编号" />
        <el-table-column prop="nickname" label="名称"/>
        <el-table-column prop="email" label="邮箱"/>
        <el-table-column prop="address" label="住址"/>
        <el-table-column prop="phoneNum" label="手机号"/>
        <el-table-column prop="sex" label="性别">
          <template slot-scope="scope">
            <el-button v-if="scope.row.sex == 0" type="primary" size="mini">女</el-button>
            <el-button v-else-if="scope.row.sex == 1" type="primary" size="mini">男</el-button>
            <el-button v-else type="primary" size="mini">未知</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="clazzName" label="所属班级" />
        <el-table-column  label="操作" width="150px" align="center">
            <template slot-scope="scope">
              <udOperation
                :data="scope.row"
                :permission="permission"
              />
            </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </el-card>



  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import crudStudent from '@/api/ceamStudent'
import eForm from './form'
import eHeader from './header'
import CRUD, { presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import udOperation from '@crud/UD.operation'

// crud交由presenter持有
const crud = CRUD({
  title: '学生信息',
  url: 'api/student',
  sort: ['sort,asc', 'id,desc'],
  crudMethod: { ...crudStudent }
})

export default {
  components: { eHeader, eForm, crudOperation, pagination, udOperation },
  mixins: [presenter(crud)],
  data() {
    return {
      delLoading: false,
      studentList: [],
      permission: {
        add: ['admin', 'teacher:add'],
        edit: ['admin', 'teacher:edit'],
        del: ['admin', 'teacher:del']
      }
    }
  },
  created() {
    this.$nextTick(() => {
      //this.init()
    })
  },
  methods: {

  }
}
</script>

<style scoped>

</style>
